package com.jiaz.untils;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author jiajiazi
 * @version 1.0
 * @date 2022/4/22 17:37
 */
@ToString
@Data
public class ResponseBean<T> implements Serializable {

    private Integer code;
    private String message;
    private T data;

    public ResponseBean(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseBean<T> success(T t) {
        return new ResponseBean<T>(200, "OK", t);
    }

    public static ResponseBean success() {
        return new ResponseBean(200, "OK", null);
    }

    public static ResponseBean error(int code, String desc) {
        return new ResponseBean(code, desc, null);
    }

    public static <T> ResponseBean<T> of(Integer code, String desc, T t) {
        return new ResponseBean<>(code, desc, t);
    }

}
